<?php

	class CategoryController extends BaseController{
		public function getList($shop_id){
			try{
				if($shop_id = Input::get('shop_id')){
               echo $json = json_encode(Categories::Select($shop_id));
            }
					
			}
			catch(Exception $e){
				return ErrorResponse::SendErrorMessage($e->getMessage());
			}
		}
		public function postRegister(){
			//checks the information input
			try{
	            $input=Input::json()->all();

	            $categories_id=InputHelper::getInput($input,'categories_id');

	            $industry_id=InputHelper::getInput($input,'industry_id');

	            $name=InputHelper::getInput($input,'name');

	            $description=InputHelper::getInput($input,'description');
	        }
	        catch(Exception $e)
	        {
            	return ErrorResponse::SendErrorMessage($e->getMessage());
        	}
        try{
            // check shop name
            
            if($category_id = Categories::Insert($categories_id,$industry_id,$name,$description))
            {
               
                    return Response::json(array('status'=>'success','id'=>$category_id));
               
            }
        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    }

	    public function postEdit(){
	    	//checks the information input

	    	try{
	            $input=Input::json()->all();

	            $categories_id=InputHelper::getInput($input,'categories_id');

	            $name=InputHelper::getInput($input,'name');

	            $industry_id=InputHelper::getInput($input,'industry_id');

	            $description=InputHelper::getInput($input,'description');
	        }
	        catch(Exception $e)
	        {
            	return ErrorResponse::SendErrorMessage($e->getMessage());
        	}
		    
	        // edit to database 
		    try{
		    	if(Categories::Edit($categories_id,$name,$description,$industry_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		}
		public function postDeletedata(){
	        $input = Input::all();
	         if (array_key_exists('categories_id', $input)) {
	            $categories_id = $input('categories_id');
	        }
	        else{

	            return ErrorResponse::SendErrorMessage('categories id invalid');
	        }
	        try{
	        	if(Categories::Deletedata($categories_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}	             
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    }
	}
?>